<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="存货大类编码" prop="cinvccode">
        <el-input
          v-model="queryParams.cinvccode"
          placeholder="请输入存货大类编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存货大类名称" prop="cinvcname">
        <el-input
          v-model="queryParams.cinvcname"
          placeholder="请输入存货大类名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['basic/inventoryclass:inventoryclass:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['basic/inventoryclass:inventoryclass:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['basic/inventoryclass:inventoryclass:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['basic/inventoryclass:inventoryclass:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="inventoryclassList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="jcInventoryclassoid" />
      <el-table-column label="存货大类编码" align="center" prop="cinvccode" />
      <el-table-column label="存货大类名称" align="center" prop="cinvcname" />
      <el-table-column label="编码级次" align="center" prop="iinvcgrade" />
      <el-table-column label="是否末级" align="center" prop="binvcend" />
      <el-table-column label="所属经济分类编码" align="center" prop="cecocode" />
      <el-table-column label="对应条形码编码" align="center" prop="cbarcode" />
      <el-table-column label="存货分类父级OID" align="center" prop="parentoid" />
      <el-table-column label="集团大类编码" align="center" prop="jtdlbm" />
      <el-table-column label="集团大类代码" align="center" prop="jtdldm" />
      <el-table-column label="排序" align="center" prop="sort" />
      <el-table-column label="使用标识" align="center" prop="sybs" />
      <el-table-column label="集团删除标识" align="center" prop="jtdel" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['basic/inventoryclass:inventoryclass:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['basic/inventoryclass:inventoryclass:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改存货分类对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="主键" prop="jcInventoryclassoid">
          <el-input v-model="form.jcInventoryclassoid" placeholder="请输入主键" />
        </el-form-item>
        <el-form-item label="存货大类编码" prop="cinvccode">
          <el-input v-model="form.cinvccode" placeholder="请输入存货大类编码" />
        </el-form-item>
        <el-form-item label="存货大类名称" prop="cinvcname">
          <el-input v-model="form.cinvcname" placeholder="请输入存货大类名称" />
        </el-form-item>
        <el-form-item label="编码级次" prop="iinvcgrade">
          <el-input v-model="form.iinvcgrade" placeholder="请输入编码级次" />
        </el-form-item>
        <el-form-item label="是否末级" prop="binvcend">
          <el-input v-model="form.binvcend" placeholder="请输入是否末级" />
        </el-form-item>
        <el-form-item label="所属经济分类编码" prop="cecocode">
          <el-input v-model="form.cecocode" placeholder="请输入所属经济分类编码" />
        </el-form-item>
        <el-form-item label="对应条形码编码" prop="cbarcode">
          <el-input v-model="form.cbarcode" placeholder="请输入对应条形码编码" />
        </el-form-item>
        <el-form-item label="存货分类父级OID" prop="parentoid">
          <el-input v-model="form.parentoid" placeholder="请输入存货分类父级OID" />
        </el-form-item>
        <el-form-item label="集团大类编码" prop="jtdlbm">
          <el-input v-model="form.jtdlbm" placeholder="请输入集团大类编码" />
        </el-form-item>
        <el-form-item label="集团大类代码" prop="jtdldm">
          <el-input v-model="form.jtdldm" placeholder="请输入集团大类代码" />
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="使用标识" prop="sybs">
          <el-input v-model="form.sybs" placeholder="请输入使用标识" />
        </el-form-item>
        <el-form-item label="集团删除标识" prop="jtdel">
          <el-input v-model="form.jtdel" placeholder="请输入集团删除标识" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInventoryclass, getInventoryclass, delInventoryclass, addInventoryclass, updateInventoryclass } from "@/api/basic/inventoryclass/inventoryclass";

export default {
  name: "Inventoryclass",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 存货分类表格数据
      inventoryclassList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cinvccode: null,
        cinvcname: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cinvccode: [
          { required: true, message: "存货大类编码不能为空", trigger: "blur" }
        ],
        cinvcname: [
          { required: true, message: "存货大类名称不能为空", trigger: "blur" }
        ],
        iinvcgrade: [
          { required: true, message: "编码级次不能为空", trigger: "blur" }
        ],
        binvcend: [
          { required: true, message: "是否末级不能为空", trigger: "blur" }
        ],
        cecocode: [
          { required: true, message: "所属经济分类编码不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询存货分类列表 */
    getList() {
      this.loading = true;
      listInventoryclass(this.queryParams).then(response => {
        this.inventoryclassList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        jcInventoryclassoid: null,
        cinvccode: null,
        cinvcname: null,
        iinvcgrade: null,
        binvcend: null,
        cecocode: null,
        cbarcode: null,
        parentoid: null,
        jtdlbm: null,
        jtdldm: null,
        sort: null,
        sybs: null,
        jtdel: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.jcInventoryclassoid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加存货分类";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const jcInventoryclassoid = row.jcInventoryclassoid || this.ids
      getInventoryclass(jcInventoryclassoid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改存货分类";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.jcInventoryclassoid != null) {
            updateInventoryclass(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInventoryclass(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const jcInventoryclassoids = row.jcInventoryclassoid || this.ids;
      this.$modal.confirm('是否确认删除存货分类编号为"' + jcInventoryclassoids + '"的数据项？').then(function() {
        return delInventoryclass(jcInventoryclassoids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('basic/inventoryclass/inventoryclass/export', {
        ...this.queryParams
      }, `inventoryclass_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
